﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch3
{
    class Deconstruct_Rectangle
    {
        public readonly float Width, Height;
        public Deconstruct_Rectangle(float width, float height)
        {
            Width = width;
            Height = height;
        }
        /// <summary>
        /// 解构器，将字段反向赋值给若干变量
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void Deconstruct(out float width,out float height)
        {
            width = this.Width;
            height = this.Height;
        }

       static void _Main(string[] args)
        {
            var rect = new Deconstruct_Rectangle(3, 4);
            // (float width, float height) = rect; //Deconstruction

            //另一种写法
            //float width, height;
            //rect.Deconstruct(out width, out height);

            //另一种写法
            rect.Deconstruct(out var width, out var height);


            Console.WriteLine(width + " " + height);       
        }
    }
}
